package com.fit.toysShop.pages;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.fit.toysShop.interfaces.Product;
import com.fit.toysShop.interfaces.Purchase;
import com.fit.toysShop.interfaces.PurchaseItem;
import com.fit.toysShop.service.Purchases;

import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.ioc.annotations.*;

public class ViewPurchase {
	@Inject
	@Property
	private Purchases purchases;

	@Property
	private Purchase currentPurchase;
	@Property
	private PurchaseItem currentPurchaseItem;

//	public Product getFirstProduct() {
//		return currentPurchase.getProducts().get(0);
//	}
	
	public Collection<PurchaseItem> getPurchaseItemCollection() {
		List<PurchaseItem> filtered = new LinkedList<PurchaseItem>();
		for (PurchaseItem purchaseItem : currentPurchase.getPurchaseItem()) {
			if (!purchaseItem.isCanceled()) filtered.add(purchaseItem);
		}
		return filtered;
	}

}
